3D Buttons is a control definition (CDEF) that implements the 3D interface as suggested in develop issue 15. When drawing on a 8-bit (or breater) color device (in a color GrafPort), 3D Buttons draws in grey. 3D Buttons drops to normal 2D drawing for black and white (or less than 8 bits of color).
The source for the 3D Buttons CDEF is broken into
• the main entry function:
3D Buttons CDEF.cp
• classes for 4 button variants:
LGBPushButtons
LGBCheckbox
LGBRadio
LIconButton
• utility functions:
LGBColorTable
LGBControl
LGBDeviceIterator
UGBDraw
• state saver/restorers
LGBClipRegion
LGBFont
LGBPen
[The "GB" stands for "Grey Buttons," which is what I originally called the project.]
I originally wrote this function in C++, but without any C++ features that require the C++ runtime engine (no destructors, no new) or A4 globals (no virtual). The CDEF was smaller and faster without all that overhead. Now that the CDEF's grown to 16K, I think the CDEF would be significantly smaller if I were to set up A4 and use inheritance, but I'm not blowing a week rewriting this CDEF just to save 8K.
Every function call into the CDEF comes through the main entry point in 3D Buttons CDEF.cp. Main() switches on the button variation and passes control to the entry point for one of the 4 button variations.
Each button variation has a main entry point that switches on the CDEF message. There are only 4 messages that button CDEFs pay attention to: draw, hit test, and 2 messages to calculate the button region.
Most of the code in each button variation is devoted to drawing the buttons. Drawing functions just save the current drawing environment, then loop through the device list, drawing either color or black and white depending on the device (screen) depth.
Change History
1.0b5—06 December 1994
Lots of bug fixes!
Fix useWFont bug—now actually uses window's font.
Save and restore font, pen color, pen state, and clip region across draw.
Clip to intersection of original clip region and device when walking device list.
Honor control and window auxilliary color tables ('cctb', 'wctb' and so on) when drawing inactive/flat controls, background of checkboxes and radio buttons.
Don't force 4 corners of pushbuttons to 0xDDDD.
Also, use classes to save/restore the pen, color, clip region.
1.0b4—31 July 1994
Bug Fix—save and restore the pen color across draws
Draw 3D buttons on 4-bit devices if those devices are also greyscale, not color.
1.0b3—29 July 1994
Added offscreen GWorld support so the button titles would stop that annoying flashing. Many thanks to one of my users for pointing it out.
1.0b2—20 July 1994 (never released)
Call PenNormal() before starting any draw. Alerts would leave the pensize at (2,2) for the default button, which tended to make OK buttons look awful in color.